package com.ruoyi.wxserver.controller;


import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import lombok.extern.slf4j.Slf4j;
import com.ruoyi.wxcommon.common.Result;
import com.ruoyi.wxserver.pojo.Server;
import com.ruoyi.wxserver.service.ServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


@RestController
@Slf4j
@RequestMapping("/server")
public class ServerController extends BaseController {
    @Autowired
    ServerService serverService;
    @GetMapping("/getinfo")
    public Result getInfo(){
        List<Server> list = serverService.selectInfo();
        return Result.SUCCESS(list);
    }
    /**
     * 查询服务管理列表
     */
    @RequiresPermissions("campusassistant:wxserver:list")
    @GetMapping("/list")
    public TableDataInfo list(Server server)
    {
        startPage();
        List<Server> list = serverService.selectServerList(server);
        return getDataTable(list);
    }

    /**
     * 导出服务管理列表
     */
    @RequiresPermissions("campusassistant:wxserver:export")
    @Log(title = "服务管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Server server)
    {
        List<Server> list = serverService.selectServerList(server);
        ExcelUtil<Server> util = new ExcelUtil<Server>(Server.class);
        util.exportExcel(response, list, "服务管理数据");
    }

    /**
     * 获取服务管理详细信息
     */
    @RequiresPermissions("campusassistant:wxserver:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serverService.selectServerById(id));
    }

    /**
     * 新增服务管理
     */
    @RequiresPermissions("campusassistant:wxserver:add")
    @Log(title = "服务管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Server server)
    {
        return toAjax(serverService.insertServer(server));
    }

    /**
     * 修改服务管理
     */
    @RequiresPermissions("campusassistant:wxserver:edit")
    @Log(title = "服务管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Server server)
    {
        return toAjax(serverService.updateServer(server));
    }

    /**
     * 删除服务管理
     */
    @RequiresPermissions("campusassistant:wxserver:remove")
    @Log(title = "服务管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serverService.deleteServerByIds(ids));
    }
}
